package com.isdoub.testcamera;

import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import com.isdoub.testcamera.camera1.Camera1Activity;
import com.isdoub.testcamera.camera2.Camera2Activity;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

    }


    public void click(View view) {
        if (Build.VERSION_CODES.M <= Build.VERSION.SDK_INT) {
            String cameraPermissiong="android.permission.CAMERA";
            int result = checkSelfPermission(cameraPermissiong);
            if (result!= PackageManager.PERMISSION_GRANTED){
                requestPermissions(new String[]{cameraPermissiong},100);
                return;
            }
        }

        Class target = null;
        if (view.getId() == R.id.bt_camera1) {
            target = Camera1Activity.class;
        } else if (view.getId() == R.id.bt_camera2) {
            target = Camera2Activity.class;
        }
        if (target == null) return;
        startActivity(new Intent(this, target));
    }


}
